package com.search;

public class MaxArea {
		static int maxArea = 0;
	public static void main(String[] args) {
		int[] a = new int[] {1,2,4,3};
		int res = maxArea(a);
		System.out.println(res);
	}
	 public static int maxArea(int[] height) {
		 	int left = 0,right = height.length - 1;
		 	while(left < right) {
		 		if(height[right] > height[left])
		 		{
		 			maxArea = Math.max(maxArea, height[left]*(right - left));
		 			left ++;
		 		}
		 		else if(height[left] > height[right]) {
		 			maxArea = Math.max(maxArea, height[right]*(right - left));
		 			right --;
		 		}
		 		else if(height[left] == height[right]) {
		 			maxArea = Math.max(maxArea, height[right]*(right - left));
			 		left ++;
			 		right --;
		 		}
			 		
		 	}
		 	return maxArea;
	 }
}
